package common

import "k8s.io/apimachinery/pkg/util/sets"

const (
	AnalysisWillFix             = "正常修复"
	AnalysisStill               = "暂不修复-漏洞仍在分析中"
	AnalysisNoPatch             = "暂不修复-暂无解决方案或补丁"
	AnalysisUpgrade             = "暂不修复-待升级版本修复"
	AnalysisOutScope            = "不修复-超出修复范围"
	AnalysisNotFix              = "不修复-特殊原因导致不再修复"
	AnalysisComponentNotPresent = "不受影响-组件不存在"
	AnalysisMitigationsExist    = "不受影响-已有内置的内联控制或缓解措施"
	AnalysisCannotControlled    = "不受影响-漏洞代码不能被攻击者触发"
	AnalysisNotExecute          = "不受影响-漏洞代码不在执行路径"
	AnalysisCodeNotPresent      = "不受影响-漏洞代码不存在"

	TypeFixed              = "Fixed"
	TypeAffected           = "Affected"
	TypeUnaffected         = "Unaffected"
	TypeUnderInvestigation = "Under Investigation"

	StateOpen       = "open"
	StateProcessing = "progressing"
	StateSuspend    = "suspended"
	StateClosed     = "closed"
)

var AnalysisUnaffected = map[string]struct{}{
	AnalysisComponentNotPresent: {},
	AnalysisMitigationsExist:    {},
	AnalysisCannotControlled:    {},
	AnalysisNotExecute:          {},
	AnalysisCodeNotPresent:      {},
}

var AnalysisEnglishMap = map[string]string{
	AnalysisWillFix:             "will fix",
	AnalysisStill:               "none_available-Vulnerabilities are still analyzing",
	AnalysisNoPatch:             "none_available-No solution or patch",
	AnalysisUpgrade:             "none_available-To be fixed through an upgraded version",
	AnalysisOutScope:            "no_fix_planned-Out of support scope",
	AnalysisNotFix:              "no_fix_planned-Will not fix",
	AnalysisComponentNotPresent: "component_not_present",
	AnalysisMitigationsExist:    "inline_mitigations_already_exist",
	AnalysisCannotControlled:    "vulnerable_code_cannot_be_controlled_by_adversary",
	AnalysisNotExecute:          "vulnerable_code_not_in_execute_path",
	AnalysisCodeNotPresent:      "vulnerable_code_not_present",
}

var (
	AnalysisSets = sets.NewString(
		AnalysisWillFix,
		AnalysisStill,
		AnalysisNoPatch,
		AnalysisUpgrade,
		AnalysisOutScope,
		AnalysisNotFix,
		AnalysisComponentNotPresent,
		AnalysisMitigationsExist,
		AnalysisCannotControlled,
		AnalysisNotExecute,
		AnalysisCodeNotPresent,
	)

	analysisStateMap = map[string]string{
		AnalysisStill:               StateSuspend,
		AnalysisNoPatch:             StateSuspend,
		AnalysisUpgrade:             StateSuspend,
		AnalysisOutScope:            StateClosed,
		AnalysisNotFix:              StateClosed,
		AnalysisComponentNotPresent: StateClosed,
		AnalysisMitigationsExist:    StateClosed,
		AnalysisCannotControlled:    StateClosed,
		AnalysisNotExecute:          StateClosed,
		AnalysisCodeNotPresent:      StateClosed,
	}

	statePriority = []string{
		StateClosed,
		StateSuspend,
		StateProcessing,
		StateOpen,
	}

	stateNameMap = map[string]string{
		StateClosed:     "已完成",
		StateSuspend:    "已挂起",
		StateProcessing: "进行中",
		StateOpen:       "待办的",
	}

	stateIdMap = map[string]int64{
		StateClosed:     437577,
		StateSuspend:    751673,
		StateProcessing: 437576,
		StateOpen:       437575,
	}
)

// GetAnalysisStateMap returns a map containing the analysis states and their corresponding values.
func GetAnalysisStateMap() map[string]string {
	return analysisStateMap
}

// GetStatePriority returns the priority of states as a slice of strings.
func GetStatePriority() []string {
	return statePriority
}

// GetStateNameMap returns a map of state names to their corresponding values.
func GetStateNameMap() map[string]string {
	return stateNameMap
}

// GetStateIdMap returns a map of state names to their corresponding IDs.
func GetStateIdMap() map[string]int64 {
	return stateIdMap
}
